//
//  DateHandel.m
//  Streaming
//
//  Created by 官琛 on 15-6-26.
//  Copyright (c) 2015年 liuxun. All rights reserved.
//

#import "DateHandel.h"

@implementation DateHandel

+(instancetype)shareHandle
{
    static DateHandel *rootVC = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        rootVC = [[DateHandel alloc]init];
    });
    
    return rootVC;
}

static sqlite3 *db = nil;
-(void)openDB
{
    if (db != nil) {
        return;
    }
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [array lastObject];
    NSString *sqlitePath = [filePath stringByAppendingPathComponent:@"dataBase.sqlite"];
    int result = sqlite3_open(sqlitePath.UTF8String, &db);
    NSLog(@"sqlitepath = %@",sqlitePath);
    if (result == SQLITE_OK) {
        NSLog(@"打开数据库");
    }
}
//热播电影
-(void)createTable
{
    NSString *sql = @"CREATE TABLE IF NOT EXISTS HotMovie(number INTEGER PRIMARY KEY AUTOINCREMENT,img TEXT,t TEXT,r INTEGER,rd TEXT,commonSpecial TEXT,NearestCinemaCount TEXT,NearestShowtimeCount TEXT,is3D TEXT,isIMAX3D TEXT,isDMAX TEXT,isNew TEXT,versions TEXT,movieId INTEGER )";
    
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //   NSLog(@"创建表成功");
        
    }
    
}


-(void)insertMovie:(Movie *)mov
{
    NSString *sql = [NSString stringWithFormat:@"INSERT INTO HotMovie (img, t, r, rd, commonSpecial, NearestCinemaCount, NearestShowtimeCount, is3D, isIMAX3D, isDMAX, isNew, versions, movieId) VALUES('%@', '%@', '%f', '%@', '%@', '%@', '%@', '%@', '%@', '%@', '%@', '%@', '%ld')",mov.img,mov.t,mov.r,mov.rd,mov.commonSpecial,mov.NearestCinemaCount,mov.NearestShowtimeCount,mov.is3D,mov.isIMAX3D,mov.isDMAX,mov.isNew,mov.versions,mov.movieId];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //NSLog(@"插入成功");
    }
}
-(void)updateTable:(Movie *)mov nameId:(NSString *)nameId
{
    NSString *sql = [NSString stringWithFormat:@"UPDATE HotMovie SET img = '%@', t = '%@', r = '%f', rd = '%@', commonSpecial = '%@', NearestCinemaCount = '%@', NearestShowtimeCount = '%@', is3D = '%@', isIMAX3D = '%@', isDMAX = '%@', isNew = '%@', versions = '%@', movieId = '%ld' WHERE movieId = '%ld'",mov.img,mov.t,mov.r,mov.rd,mov.commonSpecial,mov.NearestCinemaCount,mov.NearestShowtimeCount,mov.is3D,mov.isIMAX3D,mov.isDMAX,mov.isNew,mov.versions,mov.movieId,mov.movieId];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"修改成功");
    }
}
-(void)deleteTable:(NSString *)movieId
{
    NSString *sql = [NSString stringWithFormat:@"DELETE FROM HotMovie WHERE movieId = '%@'",movieId];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
//        NSLog(@"删除成功");
    }
}

-(NSMutableArray *)selectAllMovie
{
    NSString *sql = @"SELECT * FROM HotMovie";
    //创建数据库跟随指针对象
    sqlite3_stmt *stmt = nil;
    //查询准备操作
    //参数3.-1代表不限制sql语句长度
    //主要作用是将数据库对象db,sql语句,数据库跟随指针关联到一起,方便数据库查询操作
    int result = sqlite3_prepare_v2(db, sql.UTF8String, -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
//        NSLog(@"准备成功");
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            //取出表中每行中得每个字段的数据
            int number = sqlite3_column_int(stmt, 0);
            const unsigned char *img =  sqlite3_column_text(stmt, 1);
            const unsigned char *t = sqlite3_column_text(stmt, 2);
            float r = sqlite3_column_int(stmt, 3);
            const unsigned char *rd = sqlite3_column_text(stmt, 4);
            const unsigned char *commonSpecial = sqlite3_column_text(stmt, 5);
            const unsigned char *NearestCinemaCount = sqlite3_column_text(stmt, 6);
             const unsigned char *NearestShowtimeCount = sqlite3_column_text(stmt, 7);
            const unsigned char *is3D = sqlite3_column_text(stmt, 8);
            const unsigned char *isIMAX3D = sqlite3_column_text(stmt, 9);
            const unsigned char *isDMAX = sqlite3_column_text(stmt, 10);
            const unsigned char *isNew = sqlite3_column_text(stmt, 11);
            const unsigned char *versions = sqlite3_column_text(stmt, 12);
            int movieId = sqlite3_column_int(stmt, 13);
            Movie *mov = [[Movie alloc]init];
            mov.t = [NSString stringWithUTF8String:(const char *)t];
            mov.img = [NSString stringWithUTF8String:(const char *)img];
            mov.rd = [NSString stringWithUTF8String:(const char *)rd];
            mov.commonSpecial = [NSString stringWithUTF8String:(const char *)commonSpecial];
            mov.NearestCinemaCount = [NSString stringWithUTF8String:(const char *)NearestCinemaCount];
            mov.NearestShowtimeCount = [NSString stringWithUTF8String:(const char *)NearestShowtimeCount];
            mov.is3D = [NSString stringWithUTF8String:(const char *)is3D];
            mov.isIMAX3D = [NSString stringWithUTF8String:(const char *)isIMAX3D];
            mov.isDMAX = [NSString stringWithUTF8String:(const char *)isDMAX];
            mov.isNew = [NSString stringWithUTF8String:(const char *)isNew];
            mov.versions = [NSString stringWithUTF8String:(const char *)versions];
            mov.number = number;
            mov.movieId = movieId;
            mov.r = r;
            [array addObject:mov];
            
        }
        
        return array;
    }
    else
    {
        NSLog(@"准备失败");
    }
    //释放stmt,清除内存
    sqlite3_finalize(stmt);
    return nil;
}

-(void)dropTable
{
    
    NSString *sql = @"DROP TABLE HotMovie";
    int result =  sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"删除表成功");
    }
    
}
//即将上映
-(void)createComingTable
{
    NSString *sql = @"CREATE TABLE IF NOT EXISTS comingMovie(number INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT,image TEXT,director TEXT,releaseDate TEXT,actor1 TEXT,actor2 TEXT,wantedCount INTEGER,videoId INTEGER,movId INTEGER )";
    
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //   NSLog(@"创建表成功");
        
    }
    
}


-(void)insertcomingMovie:(Coming *)mov
{
    NSString *sql = [NSString stringWithFormat:@"INSERT INTO comingMovie (title, image, director, releaseDate, actor1, actor2, wantedCount, videoId, movId) VALUES('%@', '%@', '%@', '%@', '%@', '%@', '%ld', '%ld', '%ld')",mov.title,mov.image,mov.director,mov.releaseDate,mov.actor1,mov.actor2,mov.wantedCount,mov.videoId,mov.movId];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //NSLog(@"插入成功");
    }
}
-(void)updateComingMovieTable:(Coming *)mov nameId:(NSString *)nameId
{
    NSString *sql = [NSString stringWithFormat:@"UPDATE comingMovie SET title = '%@', image = '%@', director = '%@', releaseDate = '%@', actor1 = '%@', actor2 = '%@', wantedCount = '%ld', videoId = '%ld', movId = '%ld', movId = '%ld'",mov.title,mov.image,mov.director,mov.releaseDate,mov.actor1,mov.actor2,mov.wantedCount,mov.videoId,mov.movId,mov.movId];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"修改成功");
    }
}
-(void)deleteComingMovieTable:(NSString *)movieId
{
    NSString *sql = [NSString stringWithFormat:@"DELETE FROM comingMovie WHERE movieId = '%@'",movieId];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"删除成功");
    }
}

-(NSMutableArray *)selectAllComingMovie
{
    NSString *sql = @"SELECT * FROM comingMovie";
    //创建数据库跟随指针对象
    sqlite3_stmt *stmt = nil;
    //查询准备操作
    //参数3.-1代表不限制sql语句长度
    //主要作用是将数据库对象db,sql语句,数据库跟随指针关联到一起,方便数据库查询操作
    int result = sqlite3_prepare_v2(db, sql.UTF8String, -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
//        NSLog(@"准备成功");
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            //取出表中每行中得每个字段的数据
            int number = sqlite3_column_int(stmt, 0);
            const unsigned char *title =  sqlite3_column_text(stmt, 1);
            const unsigned char *image = sqlite3_column_text(stmt, 2);
            const unsigned char *director = sqlite3_column_text(stmt, 3);
            const unsigned char *releaseDate = sqlite3_column_text(stmt, 4);
            const unsigned char *actor1 = sqlite3_column_text(stmt, 5);
            const unsigned char *actor2 = sqlite3_column_text(stmt, 6);
            int wantedCount = sqlite3_column_int(stmt, 7);
            int videoId = sqlite3_column_int(stmt, 8);
            int movId = sqlite3_column_int(stmt, 9);
            
            Coming *mov = [[Coming alloc]init];
            mov.title = [NSString stringWithUTF8String:(const char *)title];
            mov.image = [NSString stringWithUTF8String:(const char *)image];
            mov.director = [NSString stringWithUTF8String:(const char *)director];
            mov.releaseDate = [NSString stringWithUTF8String:(const char *)releaseDate];
            mov.actor1 = [NSString stringWithUTF8String:(const char *)actor1];
            mov.actor2 = [NSString stringWithUTF8String:(const char *)actor2];
            mov.wantedCount = wantedCount;
            mov.videoId = videoId;
            mov.movId = movId;
            mov.number = number;
            
            [array addObject:mov];
            
        }
        
        return array;
    }
    else
    {
        NSLog(@"准备失败");
    }
    //释放stmt,清除内存
    sqlite3_finalize(stmt);
    return nil;
}

-(void)dropComingMovieTable
{
    
    NSString *sql = @"DROP TABLE comingMovie";
    int result =  sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"删除表成功");
    }
    
}

//排行榜ranking
-(void)createRankingTable
{
    NSString *sql = @"CREATE TABLE IF NOT EXISTS ranking(number INTEGER PRIMARY KEY AUTOINCREMENT,topListNameCn TEXT,sub TEXT )";
    
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
//           NSLog(@"创建ranking表成功");
        
    }
    
}


-(void)insertRanking:(Cemera *)cemera
{
    NSString *sql = [NSString stringWithFormat:@"INSERT INTO ranking (topListNameCn, sub) VALUES('%@', '%@')",cemera.topListNameCn,cemera.sub];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
//        NSLog(@"ranking插入成功");
    }
}
-(void)updateRankingTable:(Cemera *)cemera nameId:(NSString *)nameId
{
    NSString *sql = [NSString stringWithFormat:@"UPDATE ranking SET topListNameCn = '%@', sub = '%@' WHERE topListNameCn = '%@'",cemera.topListNameCn,cemera.sub,cemera.topListNameCn];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"修改成功");
    }
}
-(void)deleteRankingTable:(NSString *)cemera
{
    NSString *sql = [NSString stringWithFormat:@"DELETE FROM ranking WHERE topListNameCn = '%@'",cemera];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"删除成功");
    }
}

-(NSMutableArray *)selectRanking
{
    NSString *sql = @"SELECT * FROM ranking";
    //创建数据库跟随指针对象
    sqlite3_stmt *stmt = nil;
    //查询准备操作
    //参数3.-1代表不限制sql语句长度
    //主要作用是将数据库对象db,sql语句,数据库跟随指针关联到一起,方便数据库查询操作
    int result = sqlite3_prepare_v2(db, sql.UTF8String, -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
//                NSLog(@"ranking准备成功");
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            //取出表中每行中得每个字段的数据
            int number = sqlite3_column_int(stmt, 0);
            const unsigned char *topListNameCn =  sqlite3_column_text(stmt, 1);
            const unsigned char *sub = sqlite3_column_text(stmt, 2);
            Cemera *cemera = [[Cemera alloc]init];
            cemera.topListNameCn = [NSString stringWithUTF8String:(const char *)topListNameCn];
            cemera.sub = [NSString stringWithUTF8String:(const char *)sub];
            cemera.number = number;
            
            [array addObject:cemera];
            
        }
        
        return array;
    }
    else
    {
        NSLog(@"准备失败");
    }
    //释放stmt,清除内存
    sqlite3_finalize(stmt);
    return nil;
}

-(void)dropRankingTable
{
    
    NSString *sql = @"DROP TABLE ranking";
    int result =  sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"删除表成功");
    }
    
}


//热点comment
-(void)createCommentTable
{
    NSString *sql = @"CREATE TABLE IF NOT EXISTS comment(number INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT,summary TEXT,userImage TEXT,nickname TEXT,movieTitle TEXT,movieImage TEXT,idd INTEGER )";
    
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //   NSLog(@"创建表成功");
        
    }
    
}


-(void)insertComment:(coment *)comment
{
    NSString *sql = [NSString stringWithFormat:@"INSERT INTO comment (title, summary, userImage, nickname, movieTitle, movieImage, idd) VALUES('%@', '%@', '%@', '%@', '%@', '%@', '%ld')",comment.title,comment.summary,comment.userImage,comment.nickname,comment.movieTitle,comment.movieImage,comment.idd];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //NSLog(@"插入成功");
    }
}


-(NSMutableArray *)selectAllComment
{
    NSString *sql = @"SELECT * FROM comment";
    //创建数据库跟随指针对象
    sqlite3_stmt *stmt = nil;
    //查询准备操作
    //参数3.-1代表不限制sql语句长度
    //主要作用是将数据库对象db,sql语句,数据库跟随指针关联到一起,方便数据库查询操作
    int result = sqlite3_prepare_v2(db, sql.UTF8String, -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
        //        NSLog(@"准备成功");
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            //取出表中每行中得每个字段的数据
            int number = sqlite3_column_int(stmt, 0);
            const unsigned char *title =  sqlite3_column_text(stmt, 1);
            const unsigned char *summary = sqlite3_column_text(stmt, 2);
            const unsigned char *userImage = sqlite3_column_text(stmt, 3);
            const unsigned char *nickname = sqlite3_column_text(stmt, 4);
            const unsigned char *movieTitle = sqlite3_column_text(stmt, 5);
            const unsigned char *movieImage = sqlite3_column_text(stmt, 6);
            int idd = sqlite3_column_int(stmt, 7);
      
            coment *com = [[coment alloc]init];
            com.title = [NSString stringWithUTF8String:(const char *)title];
            com.summary = [NSString stringWithUTF8String:(const char *)summary];
            com.userImage = [NSString stringWithUTF8String:(const char *)userImage];
            com.nickname = [NSString stringWithUTF8String:(const char *)nickname];
            com.movieTitle = [NSString stringWithUTF8String:(const char *)movieTitle];
            com.movieImage = [NSString stringWithUTF8String:(const char *)movieImage];
            com.idd = idd;
            com.number = number;
            
            [array addObject:com];
            
        }
        
        return array;
    }
    else
    {
        NSLog(@"准备失败");
    }
    //释放stmt,清除内存
    sqlite3_finalize(stmt);
    return nil;
}

-(void)dropCommentTable
{
    
    NSString *sql = @"DROP TABLE comment";
    int result =  sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"删除表成功");
    }
    
}

//热点Real
-(void)createRealTable
{
    NSString *sql = @"CREATE TABLE IF NOT EXISTS real(number INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT,title2 TEXT,image TEXT,commentCount INTEGER,type INTEGER,idd INTEGER )";
    
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
           NSLog(@"创建Real表成功");
        
    }
    
}


-(void)insertReal:(Real *)real
{
    NSString *sql = [NSString stringWithFormat:@"INSERT INTO real (title, title2, image, commentCount, type, idd) VALUES('%@', '%@', '%@', '%ld', '%ld', '%ld')",real.title,real.title2,real.image,real.commentCount,real.type,real.idd];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"Real插入成功");
    }
}


-(NSMutableArray *)selectAllReal
{
    NSString *sql = @"SELECT * FROM real";
    //创建数据库跟随指针对象
    sqlite3_stmt *stmt = nil;
    //查询准备操作
    //参数3.-1代表不限制sql语句长度
    //主要作用是将数据库对象db,sql语句,数据库跟随指针关联到一起,方便数据库查询操作
    int result = sqlite3_prepare_v2(db, sql.UTF8String, -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
                NSLog(@"Real准备成功");
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            //取出表中每行中得每个字段的数据
            int number = sqlite3_column_int(stmt, 0);
            const unsigned char *title =  sqlite3_column_text(stmt, 1);
            const unsigned char *title2 = sqlite3_column_text(stmt, 2);
            const unsigned char *image = sqlite3_column_text(stmt, 3);
            int commentCount = sqlite3_column_int(stmt, 4);
            int type = sqlite3_column_int(stmt, 5);
            int idd = sqlite3_column_int(stmt, 6);
            
            Real *rea = [[Real alloc]init];
            rea.title = [NSString stringWithUTF8String:(const char *)title];
            rea.title2 = [NSString stringWithUTF8String:(const char *)title2];
            rea.image = [NSString stringWithUTF8String:(const char *)image];
            rea.commentCount = commentCount;
            rea.type = type;
            rea.idd = idd;
            rea.number = number;
            
            [array addObject:rea];
            
        }
        
        return array;
    }
    else
    {
        NSLog(@"准备失败");
    }
    //释放stmt,清除内存
    sqlite3_finalize(stmt);
    return nil;
}

-(void)dropRealTable
{
    
    NSString *sql = @"DROP TABLE real";
    int result =  sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"Real删除表成功");
    }
    
}

//预告片Prevue
-(void)createPrevueTable
{
    NSString *sql = @"CREATE TABLE IF NOT EXISTS Prevue(number INTEGER PRIMARY KEY AUTOINCREMENT,movieName TEXT,summary TEXT,coverImg TEXT)";
    
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"创建Prevue表成功");
        
    }
    
}

-(void)insertPrevue:(Prevue *)Prevue
{
    NSString *sql = [NSString stringWithFormat:@"INSERT INTO Prevue (movieName, summary, coverImg) VALUES('%@', '%@', '%@')",Prevue.movieName,Prevue.summary,Prevue.coverImg];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"Prevue插入成功");
    }
}

-(NSMutableArray *)selectAllPrevue
{
    NSString *sql = @"SELECT * FROM Prevue";
    //创建数据库跟随指针对象
    sqlite3_stmt *stmt = nil;
    //查询准备操作
    //参数3.-1代表不限制sql语句长度
    //主要作用是将数据库对象db,sql语句,数据库跟随指针关联到一起,方便数据库查询操作
    int result = sqlite3_prepare_v2(db, sql.UTF8String, -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
        NSLog(@"Prevue准备成功");
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            //取出表中每行中得每个字段的数据
            int number = sqlite3_column_int(stmt, 0);
            const unsigned char *movieName =  sqlite3_column_text(stmt, 1);
            const unsigned char *summary = sqlite3_column_text(stmt, 2);
            const unsigned char *coverImg = sqlite3_column_text(stmt, 3);
            
            Prevue *prevue = [[Prevue alloc]init];
            prevue.movieName = [NSString stringWithUTF8String:(const char *)movieName];
            prevue.summary = [NSString stringWithUTF8String:(const char *)summary];
            prevue.coverImg = [NSString stringWithUTF8String:(const char *)coverImg];
            prevue.number = number;
            
            [array addObject:prevue];
            
        }
        
        return array;
    }
    else
    {
        NSLog(@"准备失败");
    }
    //释放stmt,清除内存
    sqlite3_finalize(stmt);
    return nil;
}
-(void)dropPrevueTable
{
    
    NSString *sql = @"DROP TABLE Prevue";
    int result =  sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"Prevue删除表成功");
    }
    
}

//收藏
-(void)createCollectTable
{
    NSString *sql = @"CREATE TABLE IF NOT EXISTS Collect(number INTEGER PRIMARY KEY AUTOINCREMENT,title1 TEXT,idd TEXT )";
    
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //   NSLog(@"创建表成功");
        
    }
    
}


-(void)insertCollect:(web *)web
{
    NSString *sql = [NSString stringWithFormat:@"INSERT INTO Collect (title1, idd) VALUES('%@', '%@')",web.title1,web.idd];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //NSLog(@"插入成功");
    }
}
-(void)updateCollectTable:(web *)web nameId:(NSString *)nameId
{
    NSString *sql = [NSString stringWithFormat:@"UPDATE Collect SET title1 = '%@', idd = '%@' WHERE idd = '%@'",web.title1,web.idd,web.idd];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"修改成功");
    }
}
-(void)deleteCollectTable:(NSString *)idd
{
    NSString *sql = [NSString stringWithFormat:@"DELETE FROM Collect WHERE idd = '%@'",idd];
    int result = sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        //        NSLog(@"删除成功");
    }
}

-(NSMutableArray *)selectAllCollect
{
    NSString *sql = @"SELECT * FROM Collect";
    //创建数据库跟随指针对象
    sqlite3_stmt *stmt = nil;
    //查询准备操作
    //参数3.-1代表不限制sql语句长度
    //主要作用是将数据库对象db,sql语句,数据库跟随指针关联到一起,方便数据库查询操作
    int result = sqlite3_prepare_v2(db, sql.UTF8String, -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
        //        NSLog(@"准备成功");
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            //取出表中每行中得每个字段的数据
            int number = sqlite3_column_int(stmt, 0);
            const unsigned char *title1 =  sqlite3_column_text(stmt, 1);
            const unsigned char *idd =  sqlite3_column_text(stmt, 2);
            web *webm = [[web alloc]init];
            webm.title1 = [NSString stringWithUTF8String:(const char *)title1];
            webm.idd = [NSString stringWithUTF8String:(const char *)idd];
            webm.number = number;

      
            [array addObject:webm];
            
        }
        
        return array;
    }
    else
    {
        NSLog(@"准备失败");
    }
    //释放stmt,清除内存
    sqlite3_finalize(stmt);
    return nil;
}

-(void)dropCollectTable
{
    
    NSString *sql = @"DROP TABLE Collect";
    int result =  sqlite3_exec(db, sql.UTF8String, NULL, NULL, nil);
    if (result == SQLITE_OK) {
        NSLog(@"删除表成功");
    }
    
}




@end
